<?php

class Controller {

    protected $_controller;
    protected $_action;
    protected $_view;
    protected $_auto_render;
    protected $_render_header;

    function __construct($controller, $action) {
        global $inflect;
        global $session;
		global $twitter;
        global $bitly;

        $this->_auto_render = true;
        $this->_render_header = true;

        $model = ucfirst($inflect->singularize($controller));

        $this->_controller = ucfirst($controller);
        $this->$model = new $model;
        $this->_action = $action;
        $this->_view = new View($controller, $action);
        $this->session = $session;
		
		$this->twitter = $twitter;
		$this->bitly = $bitly;
    }

    function set($name, $value) {
        $this->_view->set($name, $value);
    }

    function __destruct() {
        if ($this->_auto_render) {
            $this->_view->render($this->_render_header);
        }
    }

    function render() {
        $this->_view->render($this->_render_header);
    }

    function redirect($url) {
        header("Location: ".BASE_PATH."$url");
    }

}
